from random import *
from time import *

class ThreeDoor(object):

    def __init__(self) -> None:
        seed(time())
        self.car = -1
        self.choose = -1
        self.open = -1

    def randomOrganize(self) -> None:
        self.car = randint(0, 2)

    def randomChoose(self) -> None:
        self.choose = randint(0, 2)

    def showWrongDoor(self) -> None:
        for i in range(3):
            if (i != self.car) and (i != self.choose):
                self.open = i
                break
        return

    def changeDoor(self):
        for i in range(3):
            if (i != self.choose) and (i != self.open):
                self.choose = i
                break
        return

    def rightQ(self) -> bool:
        if self.car == self.choose:
            return True

game = ThreeDoor()

change = 0
not_change = 0
N = 1000000

# change
for i in range(N):
    game.randomOrganize()
    game.randomChoose()
    game.showWrongDoor()
    game.changeDoor()
    if game.rightQ():
        change += 1

# not_change
for i in range(N):
    game.randomOrganize()
    game.randomChoose()
    game.showWrongDoor()
    if game.rightQ():
        not_change += 1

print("换门获胜率:{}%\n不换获胜率:{}%".format(change*100/N, not_change*100/N))
